<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="名称/电话号码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="handleCurrentChange(1)" class="dalfBut">查询</el-button>
                        <!--<el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>-->
                        <template>
                            <el-select v-model="value" placeholder="请选择">
                                <el-option
                                        v-for="item in options"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </template>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号" sortable min-width="10%"></el-table-column>
<!--                        <el-table-column prop="code" label="检查组编码" align="center"></el-table-column>-->
                        <el-table-column prop="name" label="姓名" align="center" sortable min-width="10%"></el-table-column>
                        <el-table-column label="性别" align="center" sortable min-width="5%">
                            <template slot-scope="scope">
                                <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                            </template>
                        </el-table-column >
                        <el-table-column prop="setmeal_name" label="预约套餐名字" align="center" sortable min-width="15%"></el-table-column>
                        <el-table-column prop="phoneNumber" label="电话号码" align="center" sortable min-width="10%"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" align="center" sortable min-width="10%"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center" sortable min-width="10%"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center" sortable min-width="10%"></el-table-column>
                        <el-table-column label="操作" align="center" sortable min-width="20%">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="体检报告基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="预约id">
                                                        <el-input v-model="formData.id" :disabled="true"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="套餐名称">
                                                        <el-input v-model="formData.setmeal" :disabled="true"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="体检时间">
                                                        <el-input v-model="formData.orderDate" :disabled="true"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="体检人">
                                                        <el-input v-model="formData.member" :disabled="true"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <template v-for="checkGroup in formData.checkGroups">
                                                <el-row>
                                                    <el-col :span="12">
                                                        <el-form-item label="检查组">
                                                            <el-input v-model="checkGroup.name" :disabled="true"/>
                                                        </el-form-item>
                                                    </el-col>
                                                </el-row>
                                                <template v-for="checkItem in checkGroup.checkItems">
                                                    <el-row>
                                                        <el-col :span="6">
                                                            <el-form-item label="检查项id">
                                                                <el-input v-model="checkItem.id" :disabled="true"/>
                                                            </el-form-item>
                                                        </el-col>
                                                        <el-col :span="8">
                                                            <el-form-item label="检查项">
                                                                <el-input v-model="checkItem.name" :disabled="true"/>
                                                            </el-form-item>
                                                        </el-col>
                                                        <el-col :span="10">
                                                            <el-form-item label="医嘱" :disabled="true">
                                                                <el-input v-model="checkItem.advice"/>
                                                            </el-form-item>
                                                        </el-col>
                                                    </el-row>
                                                </template>
                                            </template>
                                        </el-form>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                                <el-button type="primary" @click="handleUpload()">上传</el-button>
                            </div>
                        </el-dialog>
                    </div>


                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:10,
                    total:100,
                    queryString:null,
                },
                options: [{
                    value: '已到诊',
                    label: '已到诊'
                }, {
                    value: '未到诊',
                    label: '未到诊'
                },
                {
                    value: '已取消',
                    label: '已取消'
                }],
                value: '已到诊',
                dataList: [],//列表数据
                formData: {},//表单数据
                tableData:[],//新增和编辑表单中对应的检查项列表数据
                setmealIds:[],
                checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
            },
            created() {
                this.findPage();
            },
            methods: {
                //编辑
                handleEdit() {
                    axios.post('/checkresult/updateAdvice.do',this.formData).then(res => {
                        this.$message({
                            message: res.data.message,
                            type: res.data.flag?"success":"error"
                        });
                        if(res.data.flag){
                            // 关闭编辑窗口
                            this.dialogFormVisible4Edit = false;
                            // 刷新列表数据
                            this.findPage();
                        }
                    })
                },
                //上传
                handleUpload() {
                    axios.post('/checkresult/uploadedReport.do',this.formData).then(res => {
                        this.$message({
                            message: res.data.message,
                            type: res.data.flag?"success":"error"
                        });
                        if(res.data.flag){
                            // 关闭编辑窗口
                            this.dialogFormVisible4Edit = false;
                            // 刷新列表数据
                            this.findPage();
                        }
                    })
                },
                //添加
                handleAdd () {
                    // checkitemIds 通过url中key value提交，后台用@RequestParam 可以省略这个注解
                    // this.formData, 是以payload, 请求体来提交，后台用@RequestBody 来接收
                    axios.post('/ordersettinglist/add.do?setmealIds='+this.setmealIds,this.formData).then(res => {
                        this.$message({
                            message: res.data.message,
                            type: res.data.flag?"success":"error"
                        });
                        if(res.data.flag){
                            // 关闭新增窗口
                            this.dialogFormVisible = false;
                            // 刷新列表数据
                            this.findPage();
                        }
                    })
                },
                //分页查询
                findPage() {
                    axios.post('/ordersettinglist/findPage.do?option='+this.value,this.pagination).then(res => {
                        if(res.data.flag){
                            // 数据绑定
                            this.pagination.total = res.data.data.total;
                            // 分页结果集
                            this.dataList = res.data.data.rows;
                        }else{
                            this.$message.error(res.data.message);
                        }
                    })
                },
                // 重置表单
                resetForm() {
                    this.formData = {};
                    this.tableData = [];
                    this.checkitemIds = [];
                    this.setmealIds=[];
                    this.activeName = 'first';
                },
                // 弹出添加窗口
                handleCreate() {
                    this.resetForm();
                    this.dialogFormVisible = true;
                    // axios.get('/ordersettinglist/findAll.do').then(res => {
                    //     if(res.data.flag){
                    //         // 套餐
                    //         this.tableData = res.data.data;
                    //     }else{
                    //         this.$message.error(res.data.message);
                    //     }
                    // })
                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    this.resetForm();
                    this.dialogFormVisible4Edit = true;
                    var id = row.id;// 预约id
                    axios.get('/checkresult/getExaminationReport.do?id=' + id).then(res => {
                        if(res.data.flag){
                            // 检查组信息回显
                            this.formData = res.data.data;
                        }else{
                            this.$message.error(res.data.message);
                        }
                    })
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    // 修改页码
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {

                    var id = row.id; // 检查组id
                    this.$confirm('此操作将取消体检预约信息, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        // 点击确定时调用

                        axios.post('/ordersettinglist/cancelById.do?id='+id).then(res => {
                            this.$message({
                                message: res.data.message,
                                type: res.data.flag?"success":"error"
                            });
                            if(res.data.flag){
                                // 刷新列表
                                this.findPage();
                            }
                        })
                    }).catch(() => {

                    });
                },
                //已到诊
                handleArrive(row) {

                    var id = row.id; // 检查组id
                    this.$confirm('请确认会员是否已到诊', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        // 点击确定时调用

                        axios.post('/ordersettinglist/arrive.do?id='+id).then(res => {
                            this.$message({
                                message: res.data.message,
                                type: res.data.flag?"success":"error"
                            });
                            if(res.data.flag){
                                // 刷新列表
                                this.findPage();
                            }
                        })
                    }).catch(() => {

                    });
                },
            }

        })


    </script>
</html>
